package com.demoku.web.web.test;

import java.io.IOException;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.iff.infra.util.JsonHelper;
import org.iff.infra.util.mybatis.plugin.Page;
import org.iff.infra.util.mybatis.plugin.PageVo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.demoku.web.application.test.FfApplication;
import com.demoku.web.application.test.vo.FfVO;
import com.demoku.web.web.common.BaseController;

@Controller
public class FfController extends BaseController {

	@Inject
	FfApplication ffApplication;

	@RequestMapping("/ffIndex.do")
	public String index() {
		return "index";
	}
	
	@RequestMapping("/toAddFf.do")
	public String toAddFf(HttpServletRequest request, HttpServletResponse response) {
		return "test/sdfds/addFf";
	}

	@RequestMapping("/addFf.do")
	public void addFf(FfVO vo, ModelMap modelMap,
			HttpServletRequest request, HttpServletResponse response) throws IOException {
		ffApplication.saveFf(vo);
		outPrint(response, "ok");
	}
	
	@RequestMapping("/deleteFf.do")
	public void deleteFf(String id, FfVO vo, ModelMap modelMap,
			HttpServletRequest request, HttpServletResponse response) throws IOException {
		String[] allId = id.split(",");
		for(String oneId : allId) {
			ffApplication.removeFf(id);
		}
		outPrint(response, "ok");
	}
	
	@RequestMapping("/toEditFf.do")
	public String toEditFf(String id, ModelMap modelMap,
			HttpServletRequest request, HttpServletResponse response) {
		modelMap.addAttribute("ff", ffApplication.getFfVO(id));
		return "test/sdfds/editFf";
	}
	
	@RequestMapping("/editFf.do")
	public void editFf(FfVO vo, ModelMap modelMap,
			HttpServletRequest request, HttpServletResponse response) throws IOException {
		ffApplication.saveFf(vo);
		outPrint(response, "ok");
	}

	@RequestMapping("/pageFindAllFf4vo.do")
	public String pageFindAllFf(FfVO vo, ModelMap modelMap,
			HttpServletRequest request, HttpServletResponse response) {
		return "test/sdfds/pageFindAllFf";
	}
	
	@RequestMapping("/getFf4Json.do")
	public void getFf4Json(FfVO vo, ModelMap modelMap,
			HttpServletRequest request, HttpServletResponse response) throws IOException {
		Page page = ffApplication.pageFindAllFf(vo);
		outPrint(response, JsonHelper.toJson(new PageVo(page.getPageSize(), page.getTotalCount(), page.getCurrentPage(), page.getRows())));
	}
	
}
